mImages = array();
$this->mShowBytes = true;
$this->mShowFilename = true;
}
/**
* Add an image to the gallery.
*
* @param Image $image Image object that is added to the gallery
* @param string $html Additional HTML text to be shown. The name and size of the image are always shown.
*/
function add( $image, $html='' ) {
$this->mImages[] = array( &$image, $html );
}
/**
* isEmpty() returns false iff the gallery doesn't contain any images
*/
function isEmpty() {
return empty( $this->mImages );
}
/**
* Enable/Disable showing of the file size of an image in the gallery.
* Enabled by default.
*
* @param boolean $f set to false to disable
*/
function setShowBytes( $f ) {
$this->mShowBytes = ( $f == true);
}
/**
* Enable/Disable showing of the filename of an image in the gallery.
* Enabled by default.
*
* @param boolean $f set to false to disable
*/
function setShowFilename( $f ) {
$this->mShowFilename = ( $f == true);
}
/**
* Return a HTML representation of the image gallery
*
* For each image in the gallery, display
* - a thumbnail
* - the image name
* - the additional text provided when adding the image
* - the size of the image
*
*/
function toHTML() {
global $wgLang, $wgContLang, $wgUser;
$sk = $wgUser->getSkin();
$s = '
';
$i = 0;
foreach ( $this->mImages as $pair ) {
$img =& $pair[0];
$text = $pair[1];
$name = $img->getName();
$nt = $img->getTitle();
// Not an image. Just print the name and skip.
if ( $nt->getNamespace() != NS_IMAGE ) {
$s .= '' .
htmlspecialchars( $nt->getText() ) . ' | ' . (($i%4==3) ? "\n" : '');
$i++;
continue;
}
//TODO
//$ul = $sk->makeLink( $wgContLang->getNsText( Namespace::getUser() ) . ":{$ut}", $ut );
if( $this->mShowBytes ) {
if( $img->exists() ) {
$nb = wfMsg( 'nbytes', $wgLang->formatNum( $img->getSize() ) );
} else {
$nb = wfMsg( 'filemissing' );
}
$nb = htmlspecialchars( $nb ) . '
';
} else {
$nb = '';
}
'' ;
$textlink = $this->mShowFilename ?
$sk->makeKnownLinkObj( $nt, htmlspecialchars( $wgLang->truncate( $nt->getText(), 20, '...' ) ) ) . '
' :
'' ;
$s .= ($i%4==0) ? '' : '';
$thumb = $img->getThumbnail(120,120);
$s .= '' .
''.
'' .
$sk->makeKnownLinkObj( $nt, $thumb->toHtml() ) . ' | ' .
$textlink . $text . $nb;
$s .= " | \n" . (($i%4==3) ? "
\n" : '');
$i++;
}
if( $i %4 != 0 ) {
$s .= "\n";
}
$s .= '
';
return $s;
}
} //class
} // defined( 'MEDIAWIKI' )
?>